﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace MyPublisher.Composition.Fop
{
    public class FopTransform
    {
        public const string FOP_COMMAND = @"D:\mypublisher\lib\fop-0.95\fop.bat";
        #region IComposition Members

        public static void Transform(Fragments inputs, Fragment output)
        {
             //Fop foo.fo foo.pdf
             //Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)
             //Fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf
             //Fop -xml foo.xml -xsl foo.xsl -foout foo.fo
             //Fop foo.fo -mif foo.mif
             //Fop foo.fo -rtf foo.rtf
             //Fop foo.fo -print or Fop -print foo.fo
             //Fop foo.fo -awt
            Fragments outputs = new Fragments() { output};
            string parameter = string.Format(@"-c D:\mypublisher\lib\fop-0.95\conf\fop.xconf {0} {1}", inputs.ToParameter(), outputs.ToParameter());

            try
            {
                ProcessStartInfo psi = new ProcessStartInfo(FOP_COMMAND, parameter);
                psi.UseShellExecute = true;
                psi.WindowStyle = ProcessWindowStyle.Hidden;
                Process.Start(psi);
            }
            catch (Exception e)
            {
                throw new CompositionException("FopComposition failed to start FOP process.", e);
            }
        }
        #endregion
    }
}
